<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
if($submitok == "update_refresh_time"){
	if(!in_array('u_top',$QXARR))json_exit(array('flag'=>0,'msg'=>'权限不足'));
	if ( !ifint($uid))alert_adm_parent("forbidden","-1");
	$uid = intval($uid);
	$db->query("UPDATE ".__TBL_USER__." SET refresh_time=".ADDTIME." WHERE id=".$uid);
	$row2 = $db->ROW(__TBL_USER__,"nickname","id=".$uid,'num');$nickname= $row2[0];
	AddLog('刷新靠前【'.$nickname.'（uid:'.$uid.'）】');
	json_exit(array('flag'=>1,'msg'=>'操作成功，请在前台刷新页面查看效果'));
}elseif($submitok == "update_zdtime"){
	if(!in_array('u_top',$QXARR))json_exit(array('flag'=>0,'msg'=>'权限不足'));
	if ( !ifint($uid_zd) || !ifint($zdid))json_exit(array('flag'=>0,'msg'=>'forbidden'));
	$uid=intval($uid_zd);
	$row = $db->ROW(__TBL_USER__,"id,nickname","id=".$uid);
	if (!$row)json_exit(array('flag'=>0,'msg'=>'找不到此用户'));
	$nickname= trimhtml(dataIO($row[1],'out'));
	$bz = $session_uname.'后台新增';
	//
	$row = $db->ROW(__TBL_TOP_U__,"id,day","uid=".$uid,"name");
	if ($row)json_exit(array('flag'=>0,'msg'=>'此用户已经存在置顶记录（'.$row['day'].'天），请不要重复提交'));
	//
	$row = $db->ROW(__TBL_TOP__,"day","id=".$zdid,"num");
	if ($row){
		$day=$row[0];
	}else{
		json_exit(array('flag'=>0,'msg'=>'置顶项目不存在或已被删除'));
	}
	$addtime1 = ADDTIME;
	$addtime2 = ADDTIME+$day*86400;
	$db->query("INSERT INTO ".__TBL_TOP_U__."  (fid,uid,day,addtime1,addtime2,bz) VALUES ($zdid,$uid,$day,$addtime1,$addtime2,'$bz')");
	AddLog('手动增用户置顶【置顶'.$day.'天】->【'.$nickname.'（uid:'.$uid.'）】');
	json_exit(array('flag'=>1,'msg'=>'置顶新增成功'));
}
if(!in_array('u_top',$QXARR))exit(noauth());
$fid=intval($fid);
$row = $db->ROW(__TBL_TOP__,"day","id=".$fid,"num");
if ($row){
	$day=$row[0];
}else{
	exit('<br><br>置顶项目不存在或已被删除');
}
if($submitok=='add_update' || $submitok=='mod_update'){
	$uid=intval($uid);
	$row = $db->ROW(__TBL_USER__,"id,nickname","id=".$uid);
	if (!$row)alert_adm("找不到此用户","-1");$nickname= trimhtml(dataIO($row[1],'out'));
	//
	//if(!ifdatetime($addtime1) || !ifdatetime($addtime2))alert_adm("起始或结束时间不合法","-1");
	//$addtime1 = strtotime($addtime1);
	//$addtime2 = strtotime($addtime2);
	//if($addtime1 >= $addtime2)alert_adm("亲，【结束时间】必须大于【起始时间】哦","-1");
	$bz  = dataIO($bz,'in',500);
	//$day = ($addtime2-$addtime1)/86400;
}
if($submitok=='add_update'){
	$row = $db->ROW(__TBL_TOP_U__,"id","uid=".$uid);
	if ($row)alert_adm("此用户已经存在置顶记录，建议修改置顶时间即可","-1");
	$addtime1 = ADDTIME;
	$addtime2 = ADDTIME+$day*86400;
	$db->query("INSERT INTO ".__TBL_TOP_U__."  (fid,uid,day,addtime1,addtime2,bz) VALUES ($fid,$uid,$day,$addtime1,$addtime2,'$bz')");
	AddLog('手动增用户置顶【置顶'.$day.'天】->【'.$nickname.'（uid:'.$uid.'）】');
	alert_adm("新增成功","u_top_u.php?fid=".$fid);
}elseif($submitok=='mod_update'){
	if (!ifint($id))alert_adm("id参数错误","-1");
	//$db->query("UPDATE ".__TBL_TOP_U__." SET day=$day,addtime1=$addtime1,addtime2=$addtime2,bz='$bz' WHERE id=".$id);
	$db->query("UPDATE ".__TBL_TOP_U__." SET bz='$bz' WHERE id=".$id);
	AddLog('修改户置顶【置顶'.$day.'天】->【'.$nickname.'（uid:'.$uid.'）】');
	alert_adm("修改成功","u_top_u.php?fid=".$fid);
}elseif($submitok=='mod'){
	if (!ifint($id))alert_adm("id参数错误","-1");
	$rt = $db->query("SELECT * FROM ".__TBL_TOP_U__." WHERE id=".$id);
	if($db->num_rows($rt)){
		$row   = $db->fetch_array($rt,'name');
		//$day = intval($row['day']);
		$uid = intval($row['uid']);
//        $addtime1 = YmdHis($row['addtime1']);
//        $addtime2 = YmdHis($row['addtime2']);
		$bz  = dataIO($row['bz'],'out');
	}else{
		alert_adm("该记录不存在！","-1");
	}	
}elseif($submitok=='ajax_del'){
	$tmeplist = $list;
	if(empty($tmeplist))json_exit(array('flag'=>0,'msg'=>'请选择您要删除的信息'));
	if(!is_array($tmeplist))exit(JSON_ERROR);
	if(count($tmeplist)>=1){
		foreach($tmeplist as $value){$id=intval($value);
			if (!ifint($id))json_exit(array('flag'=>0,'msg'=>'记录不存在'));
			$row = $db->ROW(__TBL_TOP_U__,"uid,day","id=".$id);
			if ($row){$uid= $row[0];$day= $row[1];}else{json_exit(array('flag'=>0,'msg'=>'记录不存在'));}
			$db->query("DELETE FROM ".__TBL_TOP_U__." WHERE fid=".$fid." AND id=".$id);
			AddLog('【删除用户置顶】->【uid:'.$id.'，'.$day.'天】');
		}
	}
	json_exit(array('flag'=>1,'msg'=>'删除成功'));
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<style>
.listdatabox{padding:10px 0}
.listdatabox li{display:inline-block;padding:1px 5px;border:#ddd 1px solid;margin:3px;border-radius:3px;color:#888}
img.photo_s40{border-radius:2px;display:inline-block;;vertical-align:middle}
i.add{display:inline-block;color:#fff;border-radius:50px;width:16px;height:16px;text-align:center;font-size:12px;margin-right:2px}
i.wxlv{color:#31C93C;margin-right:2px}
.timestyle{color:#f00}
</style>
</head>
<body class="body">
<?php 
$SQL = "";
$Skey = trimhtml($Skey);
if (ifmob($Skey)){
	$SQL = " AND (U.mob=$Skey) ";
}elseif(ifint($Skey)){
	$SQL = " AND (a.uid=$Skey) ";
}elseif(!empty($Skey)){
	$SQL = " AND ( U.nickname LIKE '%".$Skey."%' OR U.truename LIKE '%".$Skey."%' )";
}
$rt = $db->query("SELECT a.id,a.uid,a.day,a.addtime1,a.addtime2,U.nickname,U.sex,U.grade,U.photo_s FROM ".__TBL_TOP_U__." a,".__TBL_USER__." U WHERE a.fid=".$fid." AND a.uid=U.id ".$SQL." ORDER BY a.id DESC");
$total = $db->num_rows($rt);
?>
<div class="navbox">
<a href="u_top_u.php?fid=<?php echo $fid;?>" <?php echo (empty($s))?' class="ed"':'';?>><?php echo $day;?>天置顶用户管理<?php echo '<b>'.$total.'</b>';?></a>
<div class="Rsobox"></div>
<div class="clear"></div></div>
<div class="fixedblank"></div>
    
<?php if($submitok=='add' || $submitok=='mod'){?>
    <form name="ZEAI_FORM" method="POST" action="<?php echo SELF;?>">
    <table class="table Mtop10 W90_ size2">
    <tr style="display:none">
      <td class="tdL">有效期</td>
      <td class="tdR"><input autocomplete="off" name="addtime1" id="addtime1" type="text" class="input size2 W200" maxlength="20" placeholder="如：<?php echo YmdHis(ADDTIME);?>" value="<?php echo $addtime1;?>" /> － <input autocomplete="off" name="addtime2" id="addtime2" type="text" class="input size2 W200" maxlength="20" placeholder="如：<?php echo YmdHis(ADDTIME+2592000);?>" value="<?php echo $addtime2;?>" /></td>
    </tr>
    <tr>
      <td class="tdL">用户UID</td>
      <td class="tdR"><input name="uid" id="uid" type="text" class="input size2 W200" value="<?php echo $uid;?>" maxlength="10" placeholder="需置顶的用户UID"  /></td>
    </tr>
    <tr>
      <td class="tdL">备注</td>
      <td class="tdR"><textarea name="bz" rows="3" class="W100_" id="bz"><?php echo $bz;?></textarea></td>
    </tr>

    </table>
    <input type="hidden" name="fid" value="<?php echo $fid;?>" />
    <?php if ($submitok == 'mod'){?>
      <input name="submitok" type="hidden" value="mod_update" />
      <input name="id" type="hidden" value="<?php echo $id;?>" />
    <?php }else{ ?>
      <input name="submitok" type="hidden" value="add_update" />
    <?php }?>
    <div class="savebtnbox"><button type="submit" class="btn size3">确认并保存</button></div>
</form>
<script src="laydate/laydate.js"></script>
<script>
/*laydate.render({
	theme: 'molv'
	,elem: '#addtime1'
	,type: 'datetime'
}); 
laydate.render({
	theme: 'molv'
	,elem: '#addtime2'
	,type: 'datetime'
}); 
*/</script>

<?php echo '</body></html>'; exit;}?>



<?php
	if ($total <= 0 ) {
		echo "<div class='nodataico Mtop50'><i></i>暂无信息";
		echo "<br><br><a class='aQINGed' href='u_top_u.php?submitok=add&fid=".$fid."'>＋手动增加置顶</a>";
		echo "</div>";
	} else {
		$page_skin = 1;$pagesize=20;require_once ZEAI.'sub/page.php';
	?>


<table class="table0 W95_ Mtop10">
<tr>
<td align="left" class="S14">
  <form name="www.yzlove.com.v6.0..QQ7144100" method="get" action="<?php echo SELF; ?>">
    <input name="Skey" type="text" id="Skey" maxlength="25" class="input size2 W200" placeholder="按UID/姓名/手机/昵称查询">
    <input type="hidden" name="fid" value="<?php echo $fid;?>" />
    <input type="submit" value="搜索" class="btn size2" />
  </form>   
</td>
<td align="left" class="S14">
</td>
<td align="right" class="S14"><a href="u_top_u.php?submitok=add&fid=<?php echo $fid;?>" class="btn size2" /><i class="ico add">&#xe622;</i>手动增加置顶</a></td>
</tr>
</table>
<div class="clear"></div>
<form id="www_zeai_cn_FORM">
    <table class="tablelist" style="width:98%;margin:10px auto 50px auto">
    <tr>
    <th width="20"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
    <th colspan="2" align="left">　置顶UID/昵称</th>
    <th width="70" align="left">起始时间</th>
    <th align="center">&nbsp;</th>
    <th width="70" align="center">结束时间</th>
    <th width="40" align="center">修改</th>
    <th width="40" align="center">删除</th>
    </tr>
    <?php
    for($i=1;$i<=$pagesize;$i++) {
        $rows = $db->fetch_array($rt,'name');
        if(!$rows) break;
        $id       = $rows['id'];
        $uid      = $rows['uid'];
        $day      = $rows['day'];
        $addtime1 = YmdHis($rows['addtime1']);
        $addtime2 = YmdHis($rows['addtime2']);
        $photo_s  = $rows['photo_s'];
        $sex      = $rows['sex'];
        $grade    = $rows['grade'];
		$nickname = trimhtml(dataIO($rows['nickname'],'out'));
		//
		$photo_s_url = (!empty($photo_s))?$_ZEAI['up2'].'/'.$photo_s:HOST.'/res/photo_s'.$sex.'.png';
    ?>
	<tr id="tr<?php echo $id;?>">
    <td width="20" height="30" align="left"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" id="id<?php echo $id; ?>" uid="<?php echo $uid; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label></td>
    <td width="60" height="30" align="center">
    <a href="javascript:;" onClick="parent.piczoom('<?php echo smb($photo_s_url,'b'); ?>');"><img class="photo_s" src="<?php echo $photo_s_url; ?>"></a></td>
    <td height="30" align="left"><?php echo uicon($sex.$grade) ?><?php echo '<font class="S14 picmiddle">'.$uid.'</font></br>　 '.$nickname;?></a></td>
    <td width="70" height="30" align="left" ><?php echo $addtime1;?></td>
    <td height="30" align="center" valign="top" style="padding-top:10px"><i class="ico S24 Cccc">&#xe62d;</i><div><?php echo zeai_djs($rows['addtime2']);?></div></td>
    <td width="70" align="center"><?php echo $addtime2;?></td>
    <td width="40" align="center"><a title="修改" fid="<?php echo $fid; ?>" clsid="<?php echo $id; ?>" class="editico"></a></td>
    <td width="40" align="center"><a title="删除" fid="<?php echo $fid; ?>" clsid="<?php echo $id; ?>" class="delico"></a></td>
    </tr>
    <?php } ?>
    <div class="listbottombox">
        <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
        <button type="button" id="btndellist" value="" class="btn HEI size2 disabled action">删除</button>　　
        <button type="button" id="btnsend" value="" class="btn size2 disabled action" onClick="sendTipFn2(this);"><i class="ico">&#xe676;</i> 发送消息</button>
        <input type="hidden" name="submitok" id="submitok" value="" />
        <?php if ($total > $pagesize)echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?></div>
    </div>
</table>
</form>
<script>
var bg = '<?php echo $_Style['list_bg']; ?>',overbg   = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
var fid='<?php echo $fid;?>';
zeai.listEach('.delico',function(obj){
	obj.onclick = function(){
		var id = parseInt(obj.getAttribute("clsid")),
		fid = parseInt(obj.getAttribute("fid"));
		zeai.confirm('确定真的要删除么（不可恢复）？',function(){
			zeai.ajax({url:'u_top_u'+zeai.ajxext+'submitok=ajax_del&fid='+fid+'&list[]='+id},function(e){var rs=zeai.jsoneval(e);
				zeai.msg(0);zeai.msg(rs.msg);
				if(rs.flag==1){setTimeout(function(){location.reload(true);},1000);}
			});
		});
	}
});
o('btndellist').onclick = function() {
	allList({
		btnobj:this,
		url:'u_top_u'+zeai.ajxext+'submitok=ajax_del&fid='+fid,
		title:'批量删除',
		msg:'正在删除中...',
		ifjson:true,
		ifconfirm:true
	});	
}
zeai.listEach('.editico',function(obj){
	obj.onclick = function(){
		var id = parseInt(obj.getAttribute("clsid")),
		fid = parseInt(obj.getAttribute("fid"));
		zeai.openurl('u_top_u'+zeai.ajxext+'submitok=mod&fid='+fid+'&id='+id);
	}
});
</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<br><br><br><br>
</body>
</html>
